<template>
  <a-card style="width: 100%">
    <a-form :form="form" layout="vertical">
      <a-row :gutter="48">
        <a-col :md="6" :sm="12">
            <a-form-item label="所在年级">
                <a-select v-decorator="[
                  'sznj',
                  {
                    rules: [{ required: true, message: '请选择所在年级!' }],
                  }
                ]">
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
            </a-form-item>
        </a-col>
         <a-col :md="6" :sm="12">
            <a-form-item label="原院系">
                <a-select v-decorator="[
                  'yyx',
                  {
                    rules: [{ required: true, message: '请选择原院系!' }],
                  }
                ]" @change="yxChange">
                    <a-select-option v-for="i in yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
            </a-form-item>
        </a-col>
         <a-col :md="6" :sm="12">
            <a-form-item label="目标院系">
                <a-select v-decorator="[
                  'xyx',
                  {
                    rules: [{ required: true, message: '请选择目标院系!' }],
                  }
                ]">
                    <a-select-option v-for="i in yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
            </a-form-item>
        </a-col>
         <a-col :md="24" :sm="24">
            <a-form-item label="需调换院系的学科">
                <a-select v-decorator="[
                  'xkdm',
                  {
                    rules: [{ required: true, message: '请选择需调换院系的学科!' }],
                  }
                ]"  mode="multiple">
                    <a-select-option v-for="i in xkList" :key="i.id" :value="i.xkdm">{{ i.xkmc }}</a-select-option>
                </a-select>
            </a-form-item>
        </a-col>
      </a-row>
      
      <a-row :span="24" style="text-align: center">
        <a-button type="primary" :loading="loadingBtn" @click="handleSave">保存</a-button>
      </a-row>
    </a-form>
  </a-card>
</template>
<script>
// import moment from 'moment'
import { mapState } from 'vuex'

export default {
  name: 'StuEditTime',
  data () {
    return {
        yxList: [],
        xkList: [],
        loadingBtn: false
    }
  },
  computed: {
    ...mapState({
      TYPE0126: state => state.app['TYPE0126'], // 年级
    })
  },
  beforeCreate () {
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.form = this.$form.createForm(this)
  },
  created () {
    this.$api.base.collegeAll().then(res => {
        this.yxList = res.data
    })
  },
  methods: {
    yxChange (code) {
      this.form.setFieldsValue({xkdm: []})
      this.$api.base.subjectAll({ssyxm: code}).then(res => {
        this.xkList = res.data
      })
    },
    // 
    // 保存操作
    handleSave () {
      this.form.validateFields((err, values) => {
        if (err) {
          return
        }
        this.loadingBtn = true
        console.log(values)
        this.$api.base.schoolRollYxzt(values).then(res => {
          this.$message.success(res.msg)
        }).finally(() => {
          this.loadingBtn = false
        })
      })
    }
  }
}
</script>
